<template>
	<z-paging ref="paging" v-model="dataList" @query="queryList">
		<view slot="top">
			<fui-search-bar @search="search" @cancel="searchCancel"></fui-search-bar>
			<fui-filter-bar :items="items" @change="change1" v-if="user.supplyer_code==0"></fui-filter-bar>
			<fui-picker :linkage="true" :options="options" :show="show" @change="change" @cancel="cancel" ></fui-picker>
			<fui-tabs :tabs="tabs" :short="false" @change="setTab"></fui-tabs>
		</view>
		<view class="list" v-for="(item,index) in dataList" @click="goUrl('/pages/msg/msg?purchase_code='+item.purchase_code)">
			<view>
				<view>供应商：{{item.supplyer_name}}</view>
				<view>订单编号：{{item.purchase_code}}</view>
			</view>
			<view style="font-size: 28rpx;color: red;">{{item.examine_status==1?'已审核':'待发货'}}</view>
		</view>
	</z-paging>
</template>

<script>
	export default {
		data() {
			return {
				// v-model绑定的这个变量不要在分页请求结束中自己赋值，直接使用即可
				show: false,
				type: 0,
				status: 0,
				supplyer_code: '',
				keyword: '',
				options: [{
					text: '1800',
					value: '1804'
				}, {
					text: '1800',
					value: '1804'
				}, {
					text: '1800',
					value: '1804'
				}],
				dataList: [],
				tabs: ['未核对', '已核对', '已付款'],
				items: [{
					text: '所属供应商',
					value: '',
					type: 'dropdown',
					active: false
				}],
				supplyer: [],
				user:[],
			};
		},
		onLoad(op) {
			this.type = op.type;
			this.user = uni.getStorageSync('user');
			console.log(this.user)
			this.$api.getSupplyer().then(res => {
				console.log(res)
				this.options = res.data;
			}).catch(err => {
				console.log(err)
				uni.showToast({
					title: err,
					icon: 'none'
				})
			})
		},
		methods: {
			search(e) {
				console.log(e.detail.value)
				this.keyword = e.detail.value;
				this.$refs.paging.reload()
			},
			searchCancel() {
				this.keyword = '';
				this.$refs.paging.reload()
			},
			setTab(e) {
				this.status = e.index;
				this.$refs.paging.reload()
			},
			// @query所绑定的方法不要自己调用！！需要刷新列表数据时，只需要调用this.$refs.paging.reload()即可
			queryList(pageNo, pageSize) {
				let self = this;
				console.log({
					type: self.type,
					status: self.status,
					supplyer_code: self.supplyer_code,
					keyword: self.keyword,
					pageNo: pageNo
				})
				this.$api.getOrder({
					type: self.type,
					status: self.status,
					supplyer_code: self.supplyer_code,
					keyword: self.keyword,
					pageNo: pageNo
				}).then(res => {
					console.log(res)
					this.$refs.paging.complete(res.data);
				}).catch(err => {
					console.log(err)
					uni.showToast({
						title: err,
						icon: 'none'
					})
					this.$refs.paging.complete(false);
				})
			},
			change(e) {
				this.show = false
				console.log('items', e)
				let items = this.items
				items[0].value = e.value
				items[0].text = e.text;
				this.items = items;
				this.supplyer_code = e.value;
				this.$refs.paging.reload()
				console.log(this.items)
			},
			cancel() {
				this.show = false
			},
			change1() {
				this.show = true;
			},
			goUrl(url) {
				uni.navigateTo({
					url: url
				})
			},
		},
	};
</script>
<style>
	.list {
		border-width: 1px;
		border-style: solid;
		border-color: rgba(121, 121, 121, 1);
		border-radius: 8px;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 20rpx;
		padding: 20rpx;
	}
</style>